package com.chenwut.threadDemo.exercise_7;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ChenPi
 * @since 2024/09/20 09:17
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable mc = new MyCallable();

        FutureTask<int[]> ft1 = new FutureTask<>(mc);
        FutureTask<int[]> ft2 = new FutureTask<>(mc);


        Thread t1 = new Thread(ft1);
        Thread t2 = new Thread(ft2);


        t1.setName("抽奖箱一");
        t2.setName("抽奖箱二");

        t1.start();
        t2.start();

        int[] ints1 = ft1.get();
        int[] ints2 = ft2.get();
        // System.out.println(ints1[0] + " " + ints1[1]);
        // System.out.println(ints2[0] + " " + ints2[1]);

        if (ints1[1] >= ints2[1]) {
            System.out.println(t1.getName() + "产生最大奖项：" + ints1[0] + "，奖项总额为：" + ints1[1]);
        } else {
            System.out.println(t2.getName() + "产生最大奖项：" + ints2[0] + "，奖项总额为：" + ints2[1]);
        }
    }
}
